package com.glxt.controller;

import com.glxt.model.UserBean;
import com.glxt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MybatisController {
    @Autowired
    private UserService userServiceImpl;
    @ResponseBody
    @GetMapping("/Mybat_All")
    public List<UserBean> Mybat_All(Model m){
        List<UserBean> UserList = userServiceImpl.findall();
        m.addAttribute("Result", UserList);
        return UserList;
    }
    @GetMapping("/Mybat_All_Page")
    public String Mybat_All_Page(Model m){
        List<UserBean> UserList = userServiceImpl.findall();
        m.addAttribute("Result", UserList);
        return "result";
    }
    @GetMapping("/Mybat_FindByid/{id}")
    public String Mybat_FindByid(@PathVariable int id, Model m){
        UserBean user = userServiceImpl.findByid(id);
        m.addAttribute("Result", user);
        return "result";
    }

//    @GetMapping("/Mybat_FindByid/{id}")
//    @ResponseBody // 自动将返回对象序列化为JSON
//    public UserBean Mybat_FindByid(@PathVariable Integer id) { // 使用Integer允许null
//        return userServiceImpl.findByid(id);
//    }


}